<?php
function controller_studio($config) {
    $db = new db($config);
	//slider
    $uploaddir = $config['image_path'].'cstudio'.DIRECTORY_SEPARATOR;
	$limitedext = array("jpg","jpeg","png","bmp");
	$cfiles = 0;
	$gambar = array();
	$files = scandir($uploaddir.'works'.DIRECTORY_SEPARATOR);
	for($i = 0; $i < count($files); $i++) {
		$file = $files[$i];
		$getExt = explode('.',$file);
		$file_ext = $getExt[count($getExt)-1];
		if (in_array($file_ext,$limitedext)) {
			$img = $config['image_url'].'cstudio/works/'.$file;
			array_push($gambar, $img);
		}
	}
	$param['slide'] = $gambar;
	//deskripsi
	$result = $db->query( "SELECT * FROM `deskripsi` WHERE page = 'cstudio'" );
	$desc = str_replace("\n", "<br />", $result[0]['deskripsi']);
	$param['deskripsi'] = $desc;
	//twitter
	$result = $db->query( "SELECT twitter FROM `footer` WHERE 1" );
	$param['twitter'] = $result[0]['twitter'];
	//works
	$result = $db->query("SELECT * FROM `cstudio` WHERE 1");
	$param['works'] = array();
	foreach ($result as $works){
		//sanggar
		$id = $works['idCstudio'];
		$param['works'][$id] = $works;
		//slider
		$uploaddir = $config['image_path'].'cstudio'.DIRECTORY_SEPARATOR.'works'.DIRECTORY_SEPARATOR;
		$gambar = array();
		$regex = $uploaddir.$id."-*";
		$limitedext = array("jpg","jpeg","png","bmp");
		//slide
		foreach (glob($regex) as $files) {
			$getFile = explode(DIRECTORY_SEPARATOR,$files);
			$file = $getFile[count($getFile)-1];
			$getExt = explode('.',$file);
			$file_ext = $getExt[count($getExt)-1];
			if (in_array($file_ext,$limitedext)) {
				$img = $config['image_url'].'cstudio/works/'.$file;
				array_push($gambar, $img);
			}
		}
		$param['works'][$id]['slide'] = $gambar;
	}
	//$param['works'] = $result;
	//
	view_studio($config, $param);
}
